Unit BDojoHandlerUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, fgl, BRequestUnit;

Type BFunctionClass = Procedure(Var aResponse: String) Of Object;

Type

{ BDojoHandlerClass }

 BDojoHandlerClass = Class
  Private
    bPath: String;
    bMethod: BFunctionClass;
  Public
    Property Path: String Read bPath;
    Property Method: BFunctionClass Read bMethod;

    Function Execute(Const aRequest: BRequestClass): Boolean;

    Constructor Build(Const aPath: String; Const aMethod: BFunctionClass);
    Destructor Burn;
End;

Type BDojoHandlersList = Specialize TFPGList<BDojoHandlerClass>;

Implementation

{ BDojoHandlerClass }

Function BDojoHandlerClass.Execute(Const aRequest: BRequestClass): Boolean;
Var
  aResponse: String;
Begin
  //TODO: set adequate check
  Result := Pos(bPath, aRequest.Headers.Values['REQUEST_URI']) > 0;
  If Result Then
    Begin
      bMethod(aResponse);
      aRequest.Response := aResponse;
    End;
End;

Constructor BDojoHandlerClass.Build(Const aPath: String;
  Const aMethod: BFunctionClass);
Begin
  bPath := aPath;
  bMethod := aMethod;
End;

Destructor BDojoHandlerClass.Burn;
Begin

End;

End.

